package com.zlf.sb.demo.completableFuture.bingxing;

import com.zlf.sb.demo.util.SmallTool;

import java.util.concurrent.CompletableFuture;

/**
 * 4.2.2 两个任务都完成了,不关注执行结果的进行下一步操作runAfterBoth/runAfterBothAsync
 */
public class CompletableFutureRunAfterBothTest {
    public static void main(String[] args) {
        SmallTool.printTimeAndThread("小白进入餐厅");
        SmallTool.printTimeAndThread("小白点了 番茄炒蛋 + 一碗米饭");

        CompletableFuture<String> cf1 = CompletableFuture.supplyAsync(() -> {
            SmallTool.printTimeAndThread("厨师炒菜");
          //  SmallTool.sleepMillis(200);
            return "番茄炒蛋";
        });
        cf1.runAfterBoth(CompletableFuture.supplyAsync(() -> {
            SmallTool.printTimeAndThread("服务员蒸饭");
            //SmallTool.sleepMillis(300);
            return "米饭";
        }), () -> {
            SmallTool.printTimeAndThread("厨师和服务员都执行完了");
        }).join();
        SmallTool.printTimeAndThread("结束");
    }
}
